def segments_intersect(a, b, c, d):
    """
    判断线段AB和线段CD是否相交

    参数:
    a, b: 线段AB的端点坐标 (x, y)
    c, d: 线段CD的端点坐标 (x, y)

    返回:
    bool: True如果线段相交，False否则
    """

    def cross_product(o, p, q):
        """计算向量op和oq的叉积"""
        return (p[0] - o[0]) * (q[1] - o[1]) - (p[1] - o[1]) * (q[0] - o[0])

    def on_segment(p, q, r):
        """判断点r是否在线段pq上"""
        if (min(p[0], q[0]) <= r[0] <= max(p[0], q[0]) and
                min(p[1], q[1]) <= r[1] <= max(p[1], q[1])):
            return True
        return False

    # 计算四个叉积
    d1 = cross_product(a, b, c)
    d2 = cross_product(a, b, d)
    d3 = cross_product(c, d, a)
    d4 = cross_product(c, d, b)

    # 情况1：线段严格相交（跨立实验）
    if ((d1 > 0 and d2 < 0) or (d1 < 0 and d2 > 0)) and \
            ((d3 > 0 and d4 < 0) or (d3 < 0 and d4 > 0)):
        return True

    # 情况2：端点在线段上（共线情况）
    # 点C在线段AB上
    if d1 == 0 and on_segment(a, b, c):
        return True

    # 点D在线段AB上
    if d2 == 0 and on_segment(a, b, d):
        return True

    # 点A在线段CD上
    if d3 == 0 and on_segment(c, d, a):
        return True

    # 点B在线段CD上
    if d4 == 0 and on_segment(c, d, b):
        return True

    return False